<?php

require_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/appconf.php');

class mapi_itrial_recomfirm extends Site {

    function setup() {
        $this->run_modes('do');
        $this->start_mode('do');
        parent::setup();
    }

    function cgiapp_prerun() {
        $this->mapi_object = getModel('MAPI_Base');
        parent::cgiapp_prerun();
    }

    function action_do() {
        $submit = intval($this->get_q('submited', 0, 'int'));
        if ($submit) {
            $aid = intval($this->get_q('aid', 0, 'int'));
            if (!$aid) {
                exit("aid 不能為空");
            }
            $_product_one = db_query_one('product_application', array('field' => 'oid,mid,application_status', 'where' => 'id=' . mysql_escape_string($aid)));
            if ($_product_one['result']) {

                db_update('product_application', array('application_status' => 7), ' id=' . mysql_escape_string($aid));
                echo $sql = "delete from member_application where mid=" . $_product_one['result']['mid'] . " and product=" . $_product_one['result']['oid'];
                db_handle($sql);
                echo "已更新數據";
            } else {
                exit("aid 錯誤！");
            }
        } else {
            echo
            '
                重置確認狀態：
                <br>
                <form method="post" action="">
                        aid:<input type="text" name="aid" size=6 /> 請小心填寫正確的aid                  
                        <input type="hidden" name="submited" value=1   />
                        <input type="submit" />
                </form>';
        }
    }

}

header("Content-type: text/html; charset=utf-8");
$webapp = new mapi_itrial_recomfirm();
$webapp->run();
?>
